/**
 * 
 */
package com.java.test.util;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import com.java.test.user.dto.PlayAccountInfo;

/**
 * @author Administrator
 *
 */

@Component
public class HttpRestUtil {

	@Autowired
	RestTemplate client;

	public String postHttp(Map<String, Object> params, String requestUrl) {
		ResponseEntity<String> responseResultResponseEntity = null;
		try {
			HttpHeaders headers = new HttpHeaders();
			MediaType type = MediaType.parseMediaType("application/json;charset=UTF-8");
			// 请勿轻易改变此提交方式，大部分的情况下，提交方式都是表单提交
			headers.setContentType(type);
			HttpEntity<Map<String, Object>> objectHttpEntity = new HttpEntity<>(params, headers); // 执行HTTP请求

			responseResultResponseEntity = client.postForEntity(requestUrl, objectHttpEntity, String.class);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		return responseResultResponseEntity.getBody();
	}

}
